﻿<?php
/**
 +------------------------------------------------------------------------------
 * CustomAction控制器类
 +------------------------------------------------------------------------------
 * @category   SubAction
 * @package  app
 * @subpackage  Custom
 * @author   朝闻道 <admin@iic.cn>
 * @date 2013-8-21
 * @time  上午10:15:35
 +------------------------------------------------------------------------------
 */
class CustomAction extends BaseAction{
	
	/**
	*问题受理和登记界面
	*@date 2013-8-21
	*@time 上午10:16:16
	*/
	function index() {
	//问题受理和登记界面
		$problem = M('user_problem');
		$where = array();
		$status = array();
		$type = array();
		$key = $_REQUEST['keywords'];
		$stype = $_REQUEST['sfield'];
		$problem_type = $_REQUEST['problem_type'];
		$solve = $_REQUEST['status'];
		if( $problem_type && $problem_type != 0 ){
				$where['tid']  = $problem_type;
		}
		$type[1] = '帐号类';
		$type[2] = '下单类';
		$type[3] = '财务类';
		$status[0] = "未答";
		$status[1] = "已答";
		if(!empty($key) && $stype != 'all'){
				$where[$stype] = array('like',"%{$key}%");
		}
		if( $solve && $solve != 'all'){
				$where['status'] = $solve;
		}
		$count = $problem->where($where)->count();
		$Page = new Page( $count,$this->listrows);	
		$res = $problem->field('id,tid,contents,attachments_url,userid,status,time')->where($where)->order('time desc')->limit($Page->firstRow.','.$Page->listRows)->select();
		$show  = $Page->show();
		$this->assign($_REQUEST);
		$this->assign('sfied',$stype);
		$this->assign('status',$status);
		$this->assign('solve',$solve);
		$this->assign('problem_type',$problem_type);
		$this->assign('totalCount',$count);	
		$this->assign('type',$type);
		$this->assign('list',$res);
		$this->display();
	}//end index
	
	function edit(){
		$where = array();
		$where['up.id'] = $_GET['id'];
		$problem = M('user_problem');
		$res = $problem->field('up.id,up.tid,up.title,up.contents,up.contacts,up.attachments_url,up.tel,userid,time,a.answer_centents,a.answer_time')->join('as up left join user_answer as a on up.id  = a.problemid')->where($where)->find();
		$this->assign('list',$res);
		$this->display();
	}
	
	function answer(){
		$answer = M('user_answer');
		$problem = M('user_problem');
		$list = array('status'=>1);
		$data = array();
		$data['answerid'] = $this->_userid;
		$data['answer_centents'] = $_POST['content'];
		$data['problemid'] = $_POST['id'];
		$data['answer_time'] = time();
		$id = $answer->add($data);
		if( $id > 0){
			$problem->where('id='.$data['problemid'])->save($list);
			$this->_ajm(200,'添加成功',1);
			
		}else{
			$this->_ajm(230,'添加失败',1);
		}
	}
	
	function sel(){
		$problem = M('user_problem');
		$answer = M('user_answer');
		$where = array();
		$id = $_GET['id'];
		if( $id ){
			$where['problemid'] = $id;
		}	
		$res = $problem->field('up.id,up.tid,up.title,up.contents,up.contacts,up.attachments_url,up.tel,userid,time,a.answer_centents,a.answer_time,a.problemid')->join('as up left join user_answer as a on up.id  = a.problemid')->where($where)->find();
		$this->assign('list',$res);
		$this->display();
	}
	
	function update(){
	
		$where = array();
		$data = array();
		$answer = M('user_answer');
		$problemid = $_POST['problemid'];
		if( $problemid ){
			$where['problemid'] = $problemid;
		}
		$content = $_POST['content'];
		if( $content ){	
			$data['answer_centents'] = $content; 
		}
		$row = $answer->where($where)->save($data);
		if( $row > 0){
			$this->_ajm(200,'追加成功',1);
		}else{
			$this->_ajm(300,'追加失败',1);
		}			
	}
	
	/**
	*历史记录查看
	*@date 2013-8-21
	*@time 上午10:17:22
	*/
	function history() {
	//历史记录查看
		
	}//end history
	
	/**
	*订单问题记录
	*@date 2013-8-21
	*@time 上午10:17:46
	*/
	function order() {
	//订单问题记录
		
	}//end order
	
	/**
	*云购问题登记
	*@date 2013-8-21
	*@time 上午10:18:08
	*/
	function yungou() {
	//云购问题登记
		
	}//end yungou
	
	/**
	*投诉建议
	*@date 2013-8-21
	*@time 上午10:18:30
	*/
	function complain() {
	//投诉建议
		
	}//end complain
	
	/**
	*财务问题登记
	*@date 2013-8-21
	*@time 上午10:18:46
	*/
	function money() {
	//财务问题登记
		
	}//end money
	
	/**
	*帐号管理
	*@date 2013-8-21
	*@time 上午10:19:09
	*/
	function accounts() {
	//帐号管理
		;
	}//end accounts
	
	/**
	*退换货记录
	*@date 2013-8-21
	*@time 上午10:19:42
	*/
	function barter() {
	//退换货记录
		
	}//end barter
	
}//end CustomAction